﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using OF.Component.Base;
using OF.Component.BLL;
using OF.Component.DTO;
using OF.Component.Model;
using OF.Utility;


namespace CWQ.Api.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    public static class JsonObjectExtensions
    {
        //public static ListOrder GetOrderAliPayAppJson(this OrderAliPayAppDto oInfo)
        //{
        //    var orderTypeText = "";
        //    var cllxText = (DicPriceOperate.GetByID(oInfo.Cllx)??new DicPriceInfo()).DicName;
        //    var contactAddress = "";
        //    var registerTime = "";
        //    var registerAddr = "";
        //    var orderStateText = "";
        //    if (oInfo.OrderCategory == 7 || oInfo.OrderCategory==8)
        //    {
        //        orderTypeText = "上线验车";
        //    }
        //    else if (oInfo.OrderCategory == 9)
        //    {
        //        orderTypeText = "领取检字";
        //    }
        //    var oLocationInfo = BaseLocation_AllOperate.GetByID(oInfo.LocationID);
        //    if (oLocationInfo != null)
        //    {
        //        contactAddress = $"{oLocationInfo.PName} {oLocationInfo.CName} {oLocationInfo.LocationName} {oInfo.Address}";
        //    }
        //    var oRegisterTime = RegisterTimeOperate.GetByID(oInfo.RegisterTimeID);
        //    if (oRegisterTime != null)
        //    {
        //        registerTime = $"{oRegisterTime.StartDate.ToDisplay("yyyy-MM-dd")} {oRegisterTime.StartDate.ToDisplay("HH:mm")}-{oRegisterTime.EndDate.ToDisplay("HH:mm")}";
        //    }
        //    var oCarOffice = CarOfficeOperate.GetByID(oInfo.RegisterAddressID);
        //    var oCarOfficeExtend = CarOfficeExtendOperate.GetByID(oInfo.RegisterAddressID);

        //    if (oCarOffice != null)
        //    {
        //        //var oLocationInfo2 = BaseLocation_AllOperate.GetByID(oCarOffice.LocationID)??new BaseLocation_AllInfo();
        //        var oLocationInfo3= BaseLocation_AllOperate.GetByID(oCarOfficeExtend.AreaId) ?? new BaseLocation_AllInfo();
        //        registerAddr = $"{oLocationInfo3.PName} {oLocationInfo3.CName} {oLocationInfo3.LocationName} {oCarOffice.Address}";
        //    }
        //    var dicList = BaseDictionaryInfoOperate.GetListByClassID(9);
        //    if (dicList.Any())
        //    {
        //        var oDic=dicList.SingleOrDefault(m => m.DictionaryValue == oInfo.OrderState);
        //        if (oDic != null)
        //        {
        //            orderStateText = oDic.DictionaryName;
        //        }
        //    }
        //    return new ListOrder
        //    {
        //        OrderID = oInfo.OrderID,//订单编号
        //        OrderTime = oInfo.CreateTime.ToDisplay("yyyy-MM-dd HH:mm"),//下单时间
        //        CarNumber=oInfo.CarLicenceNumber,//车牌号码
        //        OrderTypeText=orderTypeText,//业务类型
        //        Cllx= cllxText,//车辆类型
        //        RegisterTimeText= registerTime,//预约时间
        //        RegisterAddress = registerAddr,//预约地点
        //        OrderPrice=oInfo.OrderPrice.ToString("f2").TrimEndZeroForPrice(),//订单金额
        //        UserName=oInfo.CustomerName,//联系人
        //        Mobile=oInfo.Mobile,//联系电话
        //        IsNeedDelegateBook=oInfo.IsNeedDelegateBook==0?"否":"是",//是否需要年检委托书
        //        ContactAddress=contactAddress,//收件人联系地址
        //        OrderStateText=orderStateText,//订单状态文本
        //        OrderState=oInfo.OrderState //订单状态代码
        //    };
        //}

        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        public static void ComputeFullPostDetail(this PostDetailDto info)
        {
            IList<PostImgInfo> imgList = PostImgOperate.QueryList(a => a.PostID == info.PostID && a.PostType == info.PostType);
            imgList.ForEach(a =>
            {
                a.ImgUrl = AppSettings.GetHttpFilePath(a.ImgUrl);
            });
            if (info.HeadImgSrcType == 1)
            {
                info.HeadImgSrc = info.HeadImgSrc;
            }
            else if (info.HeadImgSrcType == 2)
            {
                info.HeadImgSrc = AppSettings.GetHttpFilePath(info.HeadImgSrc);
            }
            info.PostImgList = imgList.Select(a => a.ImgUrl).ToList();
            info.LikeUser = UserDataStatisticsOperate.GetPostLikeShopInfoByPostIdAndDataType(info.PostID, info.PostType);
            info.CommentInfo = CommentOperate.GetPostCommentShopInfoByPostIdAndDataType(info.PostID, info.PostType);
        }

    }

   
}